package com.tb.controller;

import com.tb.dubbo.IgoodsService2;
import com.tb.utils.Msg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/goods")
public class GoodsController2 {
    @Autowired
    private IgoodsService2 goodsService2;


    /*商品列表并排序*/
    @GetMapping("/list")
    public Msg getAllGoods(@RequestParam(name = "orderField",defaultValue = "")String orderField,
                           @RequestParam(name="orderType",defaultValue = "desc") String orderType,
                           @RequestParam(name="page",defaultValue ="1") int page,
                           @RequestParam(name = "rows" ,defaultValue = "10") int rows ){

            if(!orderField.equals("")&&!orderField.equals("goods_price")&&!orderField.equals("goods_sold")){
                return Msg.error(1,"参数不合法");
            } if(!orderType.equals("")&&!orderType.equals("desc")&&!orderType.equals("asc")){
                return Msg.error(1,"参数不合法");
            } if(page<=0){
                return Msg.error(1,"参数不合法");
            }

        Map<String,Object> map=new HashMap<>();
        map.put("orderField",orderField);
        map.put("orderType",orderType);
        map.put("page",page);
        map.put("rows",rows);
       return goodsService2.getAllGoods(map);
    }


}
